package org.niugang.security.log.service;

import org.niugang.security.log.dao.LogDao;
import org.niugang.security.log.pojo.LogDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;




/**
 * 日志业务
 *
 * @author Created by niugang on 2019/5/24/19:46
 */
@Service
public class LogService {

    private final LogDao logDao;

    @Autowired
    public LogService(LogDao logDao) {
        this.logDao = logDao;
    }


    public void save(LogDO logDO) {
        logDO.setFailDescription(logDO.getFailDescription() == null ? "" : logDO.getFailDescription());
        logDao.save(logDO);
    }

    public long count(){
        return  logDao.count();
    }

    public Page<LogDO> findByPage(Integer pageNo, Integer pageSize) {
        PageRequest    pageRequest = new PageRequest((pageNo-1), pageSize);
        return logDao.findAll(pageRequest);
    }
}
